Skip to content

Comments

[SSF-145] - Cognito integration account creation#113

Open
dburkhart07 wants to merge 5 commits intomainfrom
ddb/SSF-145-cognito-integration-account-creation
Open

[SSF-145] - Cognito integration account creation#113
dburkhart07 wants to merge 5 commits intomainfrom
ddb/SSF-145-cognito-integration-account-creation

Conversation

@dburkhart07
Copy link

ℹ️ Issue

Closes #145

📝 Description

This PR goes into the process of creating a new user through Cognito. Our existing Auth Service that utilized the Cognito API required a password, so we needed to use a new one that generates a temporary password, and emails it to the new user that we want to create.

When the user enters their temporary password for the first time, amplify stores a challenge that tells us that we need to create a new permanent password. Because of this, we needed to add in a new frontend modal into what we already had. From there, we can get the user cognito client sub, which is what we now store in our database.

The pantry and food manufacturer flow is slightly different, as they have linked users which are already created as they wait for approval after filling out the application. Because of that, we implement a check to see what their role is to determine if we update it in the database, or create a new user.

✔️ Verification

Run the following steps:

  • Tested users receive emails only when their email does not exist
  • Was able to successfully reset my password through the frontend UI
  • Verified pantries and food manufacturers that do not have an account receive an email, but no additional user is created (just sets the cognito client sub)

🏕️ (Optional) Future Work / Notes

Pending testing being written for this.

@Juwang110 Juwang110 self-requested a review February 23, 2026 00:51
Copy link
Member

@maxn990 maxn990 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great first pass!

In addition to the comments I left, I found one more bug I wanted to mention. After I create an account as a pantry, the first time I try to access the dashboard after creating my account I get the following problem:

Image Image

It's fine after I refresh though

Comment on lines +118 to +124
const createUserDto: userSchemaDto = {
email: pantry.pantryUser.email,
firstName: pantry.pantryUser.firstName,
lastName: pantry.pantryUser.lastName,
phone: pantry.pantryUser.phone,
role: Role.PANTRY,
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this dto is being created multiple times, think we can remove some repeat code

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not quite sure i understand this. are you referencing that we create this dto in the pantries and fm service, and because of that we should abstract it? if thats the case, im not quite sure if that abstraction is really going to save much repeat code. perhaps i am missing something though.

Comment on lines 34 to 37
firstName,
lastName,
email,
phone,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if phone is here maybe it should be included in the dto? but then we should send it to cognito.

i guess the question is what's the purpose of including the phone number:

  1. cognito uses it for mfa or invitation messages
  2. db stores it for some other reason

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i personally am fine with removing it. if we plan on adding an option for mfa verification down the line, maybe its good to include this. if not (or we just want to use email verification), then i think we are fine to just remove it in this case. @sam-schu @Yurika-Kan, thoughts?

return sub;
} catch (error) {
if (error.name == 'UsernameExistsException') {
throw new ConflictException('A user with this email already exists');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there is an email conflict doesn't it make more sense to notify the user when they submit the application rather than the admin who is approving/denying the application? there isn't really anything the admin can do if they find that an email already exists in the db other than reach out directly

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm this is a good question, and likely related to product.

for the pantry and food manufacturer flow: a DB user should be created with an empty cognito sub when the application is submitted. we could make an api call to check if the primary email exists in cognito and throw an error otherwise (since having a cognito account makes them an official user) and not allow for modal submission.

for admin and volunteers: this is a little harder, since i am not quite sure what our frontend flow is going to be for creating these two yet. how is this email going to be obtained from the frontend?

@sam-schu @Yurika-Kan

{ Name: 'email', Value: email },
{ Name: 'email_verified', Value: 'true' },
],
DesiredDeliveryMediums: ['EMAIL'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should change the email from the default to 1) indicate that their application was approved and 2) provide further information other than simply the password, like how to access the signup page, or even a link to the application. When I got the email I wasn't quite sure what to do with it

You can look at my cognito docs for instructions on how to change the default email, lmk if you have any questions

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how to access this page will definitely change, but we can just put the link as localhost for right now, and change it later, so i like the idea of more information on what to do with the password as well.

the application approved sounds good too, but im not sure if there is a separate automated email for that. i know in many modern flows (for example, email verification after you submit a job application), you receive 2 emails: one saying your application was submitted, and another being to verify your email. if we have a separate one for this, i suggest we keep the template basic on how to setup the account.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants